package com.prs.crm.action.flow;

import java.util.Collection;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;

import com.prs.crm.domain.flow.WorkFlowInstance;
import com.prs.crm.domain.flow.WorkFlowInstanceNode;
import com.prs.crm.domain.flow.WorkFlowType;
import com.prs.crm.domain.sys.Form;
import com.prs.crm.service.flow.WorkFlowInstanceService;
import com.prs.crm.vo.flow.FlowExecutor;
import com.prs.crm.vo.flow.FlowView;

public class WorkFlowViewAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	
	private WorkFlowInstanceService workflowInstanceService;
	
	private FlowView view;
	
	private FlowExecutor executor;
	
	private WorkFlowInstanceNode instanceNode;
	
	private WorkFlowInstance instance;
	
	private WorkFlowType type;
	
	private Form form;
	
	private Collection<WorkFlowInstance> instances;

	public void setWorkflowInstanceService(WorkFlowInstanceService workflowInstanceService) {
		this.workflowInstanceService = workflowInstanceService;
	}

	public WorkFlowInstanceService getWorkflowInstanceService() {
		return workflowInstanceService;
	}

	public void setView(FlowView view) {
		this.view = view;
	}

	public FlowView getView() {
		return view;
	}

	public void setType(WorkFlowType type) {
		this.type = type;
	}

	public WorkFlowType getType() {
		return type;
	}

	public void setInstances(Collection<WorkFlowInstance> instances) {
		this.instances = instances;
	}

	public Collection<WorkFlowInstance> getInstances() {
		return instances;
	}

	public void setForm(Form form) {
		this.form = form;
	}

	public Form getForm() {
		return form;
	}

	public void setInstanceNode(WorkFlowInstanceNode instanceNode) {
		this.instanceNode = instanceNode;
	}

	public WorkFlowInstanceNode getInstanceNode() {
		return instanceNode;
	}

	public void setExecutor(FlowExecutor executor) {
		this.executor = executor;
	}

	public FlowExecutor getExecutor() {
		return executor;
	}

	public void setInstance(WorkFlowInstance instance) {
		this.instance = instance;
	}

	public WorkFlowInstance getInstance() {
		return instance;
	}
	
	
	
	@Action("viewFlowInstance")
	public String execute()
	{
		return SUCCESS;
	}
	
	@Action("listFormFlowInstance")
	public String formFlowInstanceList()
	{
		this.setInstances(this.getWorkflowInstanceService().findFormInstance(form,type));
		return SUCCESS;
	}
	
	@Action("flowInstanceInfo")
	public String flowInstanceInfo()
	{
		return SUCCESS;
	}
	
	@Action(value="loadInstanceData",results={@Result(name="success",type="json",params={"root","view"})})
	public String loadInstanceData()
	{
		this.setView(this.getWorkflowInstanceService().convert(instance));
		return SUCCESS;
	}
	
	
	@Action(value="loadInstanceNodeHandler",results={@Result(name="success",type="json",params={"root","executor"})})
	public String loadInstanceNodeHandler()
	{
		this.setExecutor(this.getWorkflowInstanceService().convertHandler(instanceNode));
		return SUCCESS;
	}
}
